package scau.online.web;

import com.alibaba.fastjson.JSON;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;
import scau.cty.base.common.BaseController;
import scau.cty.base.common.IBaseService;
import scau.cty.entity.Question;
import scau.cty.entity.User;
import scau.cty.service.IUserService;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Sunlight on 2017/3/20.
 */
@ApiIgnore
@RestController
public class MyTestController extends BaseController {
    @Autowired
    private IUserService iUserService;
    @Autowired
    private IBaseService<User> userIBaseService;
//    @InitBinder
//    public void initBinder(DataBinder binder){binder.setValidator(new AddressValidator());}
//
//    @ModelAttribute
//    public User getUsername(){
//        Subject subject = SecurityUtils.getSubject();
//        String username = (String) subject.getPrincipal();
//        User user = userIBaseService.findSelectPropertyWhereAnd("username",username,"id","username").get(0);
//        user.setRoleRank(998);
//        return user;
//    }


    @GetMapping(value = "/testme",produces = "application/json")
    public String testIt(   User user){
//        if (result.hasErrors()){
//            return JSON.toJSONString("有误");
//        }
        System.out.println(user.getRoleRank()+"看下是不是没有注解也可以");
        Map map = new LinkedHashMap<>();
        List<User> list = iUserService.findAll();
        map.put("test success","success");
        map.put("list",list);
        return JSON.toJSONString(map);
    }
    @Autowired
    private IBaseService<Question> questionIBaseService;
    @GetMapping(value = "/testupdate",produces = "application/json")
    public String testUpdat(){
        Question question = new Question();
        question.setId("3");
        question.setUsername("test修改");
//        question.setQuestionContent("a");
//        question.setCreateTime(new Date());
        questionIBaseService.updateNotNull(question);
        return JSON.toJSONString("修改成功");
    }


}
